package com.yidu.ladder.base.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yidu.ladder.base.dao.StandardDao;
import com.yidu.ladder.base.domain.Standard;
import com.yidu.ladder.base.domain.StandardVo;
import com.yidu.ladder.base.service.StandardService;



@Service
public class StandardServiceImpl implements StandardService {
	@Autowired
	private StandardDao standardDao;
	public StandardDao getStandardDao() {
		return standardDao;
	}
	public void setStandardDao(StandardDao standardDao) {
		this.standardDao = standardDao;
	}
	public StandardServiceImpl() {
		super();
	}

	public StandardServiceImpl(StandardDao standardDao) {
		super();
		this.standardDao = standardDao;
	}
	@Override
	public Map<String, Object> pageQuerystandard(StandardVo standardVo) {
		int page = (standardVo.getPage() - 1) * standardVo.getLimit();
		standardVo.setPage(page);
		List<Standard> query = standardDao.pageQuerystandard(standardVo);
		int count = standardDao.countUserByCriteria(standardVo);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("count", count);
		map.put("data", query);
		return map;
	}
	@Override
	public Boolean updatefreeze(String standardIdstr, String flag) {
		Map<String, Object> paraMap = new HashMap<String, Object>();
		String userable = flag;
		String[] standardIds = standardIdstr.split(",");
		int total = 0;
		for (int i = 0; i < standardIds.length; i++) {
			// 添加ID
			paraMap.put("standardId", standardIds[i]);
			paraMap.put("userable", userable);
			int result = standardDao.updatefreeze(paraMap);
			total += result;
		}
		return total == standardIds.length ? true : false;
	}
	@Override
	public int addstaff(Standard standard) {
		return standardDao.addstandard(standard);
	}
	@Override
	public int updatepicture(Standard standard) {
	
	int updateStaff	=standardDao.updateStaff(standard);
	int update=standardDao.update(standard);
	if(updateStaff==1&&update==1) {
			return 1;
	}else {
		return 0;
	}
	}
}